home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0025_AsciiZ Strings.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  877b  |  55 lines

  1. {
  2. SEAN PALMER
  3.  
  4. these routines change formats 'in place' without changing the number of
  5. bytes, ever, so you can safely use $V-
  6. }
  7.  
  8. unit asciiz;  {routines for converting strings to asciiz and back}
  9.  
  10. interface
  11.  
  12. procedure asciiz2string(var a : string);
  13. procedure string2asciiz(var s : string);
  14.  
  15. implementation
  16.  
  17. {note: any asciiz must be length 255 or less}
  18.  
  19. procedure asciiz2string(var a : string); assembler;
  20. asm
  21.   push ds
  22.   cld
  23.   lds  si, a
  24.   mov  cx, 0
  25.  @L:
  26.   xchg al, byte ptr[si]
  27.   inc  si
  28.   or   al, al
  29.   jnz  @L
  30.   mov  ax, si
  31.   mov  si, word ptr a
  32.   sub  ax, si   {calc length}
  33.   dec  ax
  34.   mov  [si], al
  35.   pop  ds
  36. end;
  37.  
  38. procedure string2asciiz(var s : string); assembler;
  39. asm
  40.   push  ds
  41.   lds   si, s
  42.   les   di, s
  43.   lodsb
  44.   mov   cl, al
  45.   xor   ch, ch
  46.   cld
  47.   rep   movsb
  48.   xor   al, al
  49.   stosb
  50.   pop   ds
  51. end;
  52.  
  53. end.
  54.  
  55.